import { request } from '@umijs/max';

// 获取位置信息
const getAddress = async (ip?: number) => {
  if (ip) {
    return request<COMMON.BaiDuLocation>(
      `/baidu/location/ip?ak=${BAI_DU_WEB_AK}&ip=${ip}&coor=bd09ll`,
      {
        method: 'GET',
      },
    );
  }
  return request<COMMON.BaiDuLocation>(`/baidu/location/ip?ak=${BAI_DU_WEB_AK}&coor=bd09ll`, {
    method: 'GET',
  });
};

const getWeather = async (addressCode: number | string) => {
  return request<COMMON.CurrentWeather>(
    `/baidu/weather/v1/?district_id=${addressCode}&data_type=all&ak=${BAI_DU_SERVICE_AK}`,
    {
      method: 'GET',
    },
  );
};

export { getAddress, getWeather };
